﻿using SqlSugar;
using BasicModuleOrm.Model;

namespace BasicModuleOrm.Db_Context
{
    public class SqlSugarContext
    {
        public IConfiguration Configuration { get; set; }
        public SqlSugarClient sqlSugarClient; // 全局使用

        public SqlSugarContext()
        {
            //1、创建SqlSugarClient
            sqlSugarClient = new SqlSugarClient(new ConnectionConfig()
            {
                // 1.1、配置连接地址
                ConnectionString = "server=192.168.60.129;port=3306;database=AspNetCore_ORMs;uid=root;pwd=123456",
                DbType = DbType.MySql, // 选择MySQL数据库
                IsAutoCloseConnection = true,
            });

            // 2、配置模型(模型生成表)
            sqlSugarClient.CodeFirst.InitTables<Order>();
            sqlSugarClient.CodeFirst.InitTables<User>();
        }
    }
}
